package com.lizheng.yunservice.travel.controller;

import com.lizheng.yunservice.common.domain.ApiRestResponse;
import com.lizheng.yunservice.travel.doamin.VtpScenic;
import com.lizheng.yunservice.travel.doamin.vo.ScenicVo;
import com.lizheng.yunservice.travel.doamin.vo.VtpAppScenicListVo;
import com.lizheng.yunservice.travel.doamin.vo.VtpScenicCategoryVo;
import com.lizheng.yunservice.travel.service.VtpAppScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/vtp/app/scenic")
public class VtpAppScenicController {

    @Autowired
    private VtpAppScenicService vtpAppScenicService;

    @GetMapping("/getNearScenicList")
    public ApiRestResponse<List<ScenicVo>> getNearScenicList(
            @RequestParam Double longitude,
            @RequestParam Double latitude) {

        List<VtpScenic> scenicList = vtpAppScenicService.findNearbyScenicSpots(longitude, latitude);

        List<ScenicVo> scenicVos = scenicList.stream().map(scenic -> {
            ScenicVo vo = new ScenicVo();

            // 复制所有基础字段
            vo.setScenicId(scenic.getScenicId());
            vo.setScenicNo(scenic.getScenicNo());
            vo.setScenicName(scenic.getScenicName());
            vo.setAncientName(scenic.getAncientName());
            vo.setLogoUrl(scenic.getLogoUrl());
            vo.setSiftImgUrl(scenic.getSiftImgUrl());
            vo.setAudioUrl(scenic.getAudioUrl());
            vo.setVrUrl(scenic.getVrUrl());
            vo.setSummary(scenic.getSummary());
            vo.setFeatures(scenic.getFeatures());
            vo.setPropaganda(scenic.getPropaganda());
            vo.setContent(null);
            vo.setProvinceId(scenic.getProvinceId());
            vo.setCityId(scenic.getCityId());
            vo.setDistrictId(scenic.getDistrictId());
            vo.setAddress(scenic.getAddress());
            vo.setLongitude(scenic.getLongitude());
            vo.setLatitude(scenic.getLatitude());
            vo.setShowStatus(scenic.getShowStatus());
            vo.setStatus(scenic.getStatus());
            vo.setDistance(scenic.getDistance().intValue());
            vo.setCityName(vtpAppScenicService.findProvince(scenic.getCityId()));
            vo.setProvinceName(vtpAppScenicService.findProvince(scenic.getProvinceId()));
            vo.setDistrictName(vtpAppScenicService.findProvince(scenic.getDistrictId()));
            vo.setImgs(null);
            vo.setVideos(null);
            vo.setHistorys(null);
            vo.setCategoryIds(null);
            // 时间字段
            vo.setCreateTime(null);
            vo.setUpdateTime(null);
            return vo;
        }).collect(Collectors.toList());

        return ApiRestResponse.ok(scenicVos);
    }

    @GetMapping("/getScenicCategoryList")
    public ApiRestResponse<List<VtpScenicCategoryVo>> getScenicCategoryList() {
        // 模拟获取景点列表
        List<VtpScenicCategoryVo> scenicCategoryList = vtpAppScenicService.getScenicCategoryList();

        return ApiRestResponse.ok(scenicCategoryList);
    }

    @GetMapping("/getScenicList/{id}")
    public ApiRestResponse<List<VtpAppScenicListVo>> getScenicList(@PathVariable Long id) {
        List<VtpAppScenicListVo> scenicList = vtpAppScenicService.getScenicList(id);
        return ApiRestResponse.ok(scenicList);
    }
}